package main

import (
	"fmt"
	"log"
	"net"
)

func HandleConn(conn net.Conn) {
	defer conn.Close()
	buf := make([]byte, 1024)
	n, err := conn.Read(buf)
	if err != nil {
		log.Println(err.Error())
		return
	}
	fmt.Println("从客户端读取到数据:", string(buf[:n]))
	conn.Write([]byte("close"))
	conn.Close()
}

func main() {
	listen, err := net.Listen("tcp", ":8888")
	if err != nil {
		log.Fatal(err)
		return
	}
	for {
		conn, err := listen.Accept()
		if err != nil {
			log.Fatal(err)
			continue
		}
		go HandleConn(conn)
	}
}
